package com.gaofans.nrpc.client.bootstrap;

import com.gaofans.nrpc.common.compress.Codec;
import com.gaofans.nrpc.common.serializer.SerializerFactory;
import com.gaofans.nrpc.common.id.IdGenerator;
import io.netty.channel.ChannelOption;
import io.netty.handler.ssl.SslContext;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

/**
 * @author GaoFans
 */
@SuppressWarnings("rawtypes")
public class ChannelBootstrapConfig {

    /**
     * nio loop线程数
     */
    private int eventLoopThreadCount;
    /**
     * 对每次请求进行分发的 loop 线程数
     */
    private int workerThreadCount;

    /**
     * 业务处理的线程数
     */
    private int handlerThreadCount;

    /**
     * netty的相关配置
     */
    private final Map<ChannelOption, Object> optionMap = new HashMap<>();

    /**
     * 序列化器的工厂类
     */
    private SerializerFactory serializerFactory;

    /**
     * 序列化的类型
     */
    private byte serializerType;

    /**
     * 请求的版本
     */
    private short version;

    /**
     * 请求的编码器
     */
    private Codec codec;

    /**
     * 每次请求的id生成器
     */
    private IdGenerator idGenerator;

    /**
     * 每个请求对应的响应处理器的过期时间
     */
    private Duration processorExpireTime;

    /**
     * 每个请求对应的响应处理器的最大数量
     */
    private long processorMaximumSize;

    /**
     * 心跳的读超时时间，秒
     */
    private int readerIdleTimeSecond = 20;

    /**
     * 心跳的写超时时间，秒
     */
    private int writerIdleTimeSecond = 15;

    /**
     * 开启ssl连接所需的context，null则不开启
     */
    private SslContext sslContext;

    public int getEventLoopThreadCount() {
        return eventLoopThreadCount;
    }

    public void setEventLoopThreadCount(int eventLoopThreadCount) {
        this.eventLoopThreadCount = eventLoopThreadCount;
    }

    public int getWorkerThreadCount() {
        return workerThreadCount;
    }

    public void setWorkerThreadCount(int workerThreadCount) {
        this.workerThreadCount = workerThreadCount;
    }

    public int getHandlerThreadCount() {
        return handlerThreadCount;
    }

    public void setHandlerThreadCount(int handlerThreadCount) {
        this.handlerThreadCount = handlerThreadCount;
    }

    public SerializerFactory getSerializerFactory() {
        return serializerFactory;
    }

    public Map<ChannelOption, Object> getOptionMap() {
        return optionMap;
    }

    public void setOptionMap(ChannelOption key,Object value) {
        this.optionMap.put(key,value);
    }

    public void setSerializerFactory(SerializerFactory serializerFactory) {
        this.serializerFactory = serializerFactory;
    }

    public byte getSerializerType() {
        return serializerType;
    }

    public void setSerializerType(byte serializerType) {
        this.serializerType = serializerType;
    }

    public short getVersion() {
        return version;
    }

    public void setVersion(short version) {
        this.version = version;
    }

    public Codec getCodec() {
        return codec;
    }

    public void setCodec(Codec codec) {
        this.codec = codec;
    }

    public IdGenerator getIdGenerator() {
        return idGenerator;
    }

    public void setIdGenerator(IdGenerator idGenerator) {
        this.idGenerator = idGenerator;
    }

    public Duration getProcessorExpireTime() {
        return processorExpireTime;
    }

    public void setProcessorExpireTime(Duration processorExpireTime) {
        this.processorExpireTime = processorExpireTime;
    }

    public long getProcessorMaximumSize() {
        return processorMaximumSize;
    }

    public void setProcessorMaximumSize(long processorMaximumSize) {
        this.processorMaximumSize = processorMaximumSize;
    }

    public int getReaderIdleTimeSecond() {
        return readerIdleTimeSecond;
    }

    public void setReaderIdleTimeSecond(int readerIdleTimeSecond) {
        this.readerIdleTimeSecond = readerIdleTimeSecond;
    }

    public int getWriterIdleTimeSecond() {
        return writerIdleTimeSecond;
    }

    public void setWriterIdleTimeSecond(int writerIdleTimeSecond) {
        this.writerIdleTimeSecond = writerIdleTimeSecond;
    }

    public SslContext getSslContext() {
        return sslContext;
    }

    public void setSslContext(SslContext sslContext) {
        this.sslContext = sslContext;
    }
}
